package xyz.zcq.zcqrpc.protocol;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * 协议消息的序列化器 枚举
 */
@Getter
public enum ProtocolMessageSerializerEnum {
    JDK(0, "jdk"),
    JSON(1, "json"),
    KRYO(2, "kryo"),
    HESSIAN(3, "hessian"),
    ;

    private final int key;
    private final String value;

    ProtocolMessageSerializerEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    public static ProtocolMessageSerializerEnum getByKey(int key) {
        for (ProtocolMessageSerializerEnum pms : ProtocolMessageSerializerEnum.values()) {
            if (pms.key == key) {
                return pms;
            }
        }

        return null;
    }

    public static ProtocolMessageSerializerEnum getByValue(String value) {
        if (ObjectUtil.isEmpty(value)) {
            return null;
        }
        for (ProtocolMessageSerializerEnum anEnum : ProtocolMessageSerializerEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

}
